<template>
	<view class="info">
		<image class="info_img" :src="imgPath+dataobj.images" mode=""></image>
		<view class="info_head">
			<view class="font-1e1e1e font15 font-b">{{dataobj.name}}</view>
			<view class="flex-row-start" style="margin-top: 10rpx;">
				<view class="font-ff6428 font13">
					<text v-if="dataobj.pay_status == 1 || dataobj.pay_status == 3" class="font17">{{dataobj.score}}</text>
					<text v-if="dataobj.pay_status == 1 || dataobj.pay_status == 3">积分</text>
					<text v-if="dataobj.pay_status == 3">+</text>
					<text v-if="dataobj.pay_status == 2 || dataobj.pay_status == 3">￥{{dataobj.price}}</text>
				</view>
				<view class="font-969696 font11 font-line" style="margin-left: 6rpx;">
					<text>{{dataobj.line_score}}</text>
					<text>积分</text>
					<text v-if="dataobj.line_price&&(dataobj.pay_status == 2 || dataobj.pay_status == 3)">
						<text>+</text>
						<text>￥{{dataobj.line_price}}</text>
					</text>
				</view>
			</view>
		</view>
		<view class="info-border"></view>
		<view class="info-bos flex-column-center">
			<view class="font17 font-b" style="margin-bottom: 10rpx;">商品详情</view>
			<rich-text class="font13" :nodes="dataobj.content"></rich-text>
			<image v-if="dataobj.is_platform == 1" style="height: 1200rpx;" src="../../../static/ComTabBar/abc.jpg" mode=""></image>
			<image v-if="dataobj.is_platform == 1" :show-menu-by-longpress='true' style="height: 650rpx;" src="../../../static/ComTabBar/code.jpg" mode=""></image>
			<!-- <view class="font13">纯棉时代棉柔巾</view> -->
			<!-- <view class="font17 font-b" style="margin-top: 20rpx;">权益介绍</view>
			<view>
				<view class="font16" style="margin-top: 10rpx;">使用规则</view>
				<view class="font14" style="margin: 10rpx 0;">兑换须知</view>
				<view class="font13">加入纽宾凯会员，权权益为纽宾凯会员专享，加入纽宾凯会员，权权益为纽宾凯会员专享</view>
			</view> -->
		</view>
		<view class="info-bnt flex-row-center" @click="onPopup">
			<view>立即兑换</view>
		</view>
		<view class="info-bnt1"></view>
		<!-- 购物车选择 -->
		<uni-popup ref="popup" type="bottom">
			<view class="info_choice">
				<view class="choice_title">
					<view class="title_bos">
						<image :src="imgPath+dataobj.logo" mode="">
						</image>
						<view class="title_box">
							<view class="font-ff3c37">
								<text class="font17">{{dataobj.score}}</text>
								<text>积分</text>
								<text v-if="dataobj.price">
									<text>+</text>
									<text>￥{{dataobj.price}}</text>
								</text>
							</view>
							<!-- 	<view class="font-969696 font11">库存 {{findItem.stock_num?findItem.stock_num:dataobj.maxnum}}
								件</view> -->
							<view class="font-969696 font11">
								<text>已选择:{{dataobj.name}}</text>
							</view>
						</view>
					</view>
					<image @click="Onclose" class="title_fork" src="https://newbeaconyt.oss-cn-hangzhou.aliyuncs.com/app/hotel/fork.png" mode=""></image>
				</view>
				<view class="choice_border"></view>
				<view class="choice_bos">
					<view class="choice_list" v-for="(item,index) in dataobj.spec" :key="index">
						<view class="font-1e1e1e font13">{{item.spec_name}}</view>
						<view class="choice_lists" v-for="(item1,index1) in item.value" :key="index1">
							<view class="font12" @click="Onchoice(item1,index,index1)"
								:class="!item1.show?'font-969696':goodsIndex[index] == index1?'font-ff3c37 back-ffe9e8':'font-323232'">
								{{item1.spec_value}}
							</view>
						</view>
						<view class="choice_border margin-t20"></view>
					</view>
				</view>
				<view class="choice_num flex-row-between">
					<view class="font-1e1e1e font13 choice_nums">数量</view>
					<view class="number_bos">
						<view class="flex-row-center number_box" @click="Onnum('rec')">
							<image class="number_reduce" src="https://newbeaconyt.oss-cn-hangzhou.aliyuncs.com/app/hotel/reduce.png" mode=""></image>
						</view>
						<input @input="Oninputnum" class="number_num font-1e1e1e font13" type="number"
							:value="goods_number" />
						<view class="flex-row-center number_box" @click="Onnum('add')">
							<image class="number_add" src="https://newbeaconyt.oss-cn-hangzhou.aliyuncs.com/app/hotel/add.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="choice_border"></view>
				<view class="choice_buttom flex-row-center" @click="onPath">
					<view class="font-ffffff font13 flex-row-center">{{typeis=='cart'?'加入购物车':'立即购买'}}</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: null,
				dataobj: {},
				imgPath: this.$Config.http_static, // 图片头
				goods_number: 1,
			}
		},
		onLoad: function(options) {
			this.id = options.id
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$Http({
					url: 'goodsDetails',
					token: true,
					data: {
						id: this.id
					}
				}).then(res => {
					if (res.code == 1) {
						res.data.content = res.data.content?res.data.content.replace(/\<img/g,'<img style="display: block;max-width: 100%;height: auto;"'):''
						this.dataobj = res.data
					}
				});
			},
			onPopup() {
				this.$refs.popup.open()
			},
			//关闭弹窗
			Onclose() {
				this.$refs.popup.close()
			},
			//数量
			Onnum(e) {
				if (e == 'add') {
					if(this.dataobj.is_platform == 1){
						this.goods_number = 1
						return
					}
					this.goods_number++
				} else {

					if (this.goods_number == 1) {
						this.goods_number = 1
						return
					}
					this.goods_number--
				}
			},
			Oninputnum(e) {
				let val = e.detail.value
				this.goods_number = val
			},
			onPath(url) {
				if (this.goods_number < 1) {
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: '购买数量不能小于1'
					});
					return
				}
				if(this.dataobj.is_platform == 1 && this.goods_number>1){
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: '购买数量只能为1'
					});
					return
				}
				this.$Http({
					url: 'createOrder',
					token: true,
					load: true,
					type: 'POST',
					data: {
						goods_id: this.id,
						goods_number: this.goods_number
					}
				}).then(res => {
					if (res.code == 1) {
						uni.navigateTo({
							url: '/pages/integral/ferry?id='+res.data.order_id
						});
					}else{
						uni.showToast({
							icon: 'none',
							duration: 2000,
							title: res.msg
						});
					}
				});
			}
		}
	}
</script>

<style lang="less">
	@import url("info.less");
</style>